#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int main(int argc, char* argv[])
{
    int i = 0;
    int c = 0;
    int iflg = 0;
    int fflg = 0;
    int sflg = 0;
    char* fvalue = NULL;
    char* svalue = NULL;
    
    while( (c = getopt(argc, argv, "f:is::")) != -1 )
    {
        switch( c )
        {
            case 'f':
                fflg = 1;
                fvalue = optarg;
                break;
            case 'i':
                iflg = 1;
                break;
            case 's':
                sflg = 1;
                svalue = optarg;
                break;
            case '?':
                printf("Unknow option: -%c\n", optopt);
                break;
            case ':':
                printf("-%c missing option argument\n", optopt);
                break;
            case 1:
                printf("inter: %s\n", optarg);
                break;
            default:
                printf("ret = %d\n", c);
        }
    }
    
    printf("fflg = %d, fvalue = %s, iflg = %d, sflg = %d, svalue = %s\n", fflg, fvalue, iflg, sflg, svalue);
    
    for(i=optind; i<argc; i++)
    {
        printf("parameter: %s\n", argv[i]);
    }
    
    return 0;
}
